package com.mrd.gtimp.business.service;

import com.mrd.base.BaseBiz;
import com.mrd.gtimp.business.entity.ContractTerms;
import com.mrd.gtimp.business.entity.Declaration;
import com.mrd.spring.repository.BaseRepository;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

import javax.annotation.Resource;

/**
 * <p> application name: gtimp <p> copyright: Copyright@2012 明睿达科技有限公司
 */

/**
 * @author yangyl
 */
@Service
public class ContractTermsBiz extends BaseBiz<ContractTerms> {


    @Resource
    // 该处指定注入BaseRepository的dao对象
    @Qualifier("contractTermsDao")
    public void setBaseRepository(BaseRepository<ContractTerms, String> baseRepository) {
        super.baseRepository = baseRepository;
    }

    public ContractTerms findEntityByDeclaration(Declaration declaration){
        if(StringUtils.isNotEmpty(declaration.getId())){
            String hql = "from com.mrd.gtimp.business.entity.ContractTerms contractTerms where contractTerms.declaration.id='"+declaration.getId()+"'";
            List<ContractTerms> list = this.findEntityByHql(hql,0,10,null);
            if(!list.isEmpty() && list.size()>0){
                return list.get(0);
            }
        }
        return null;
    }

}
